<?php
/**
 * Created by PhpStorm.
 * User: zc
 * Date: 2019/8/5
 * Time: 23:36
 */
namespace app\api\controller\v1;

use app\common\controller\Api;
use app\common\logic\SearchLogic;

class Search extends Api
{
    protected $noNeedLogin = [];  //不能登陆方法
    protected $noNeedRight = '*';
    /**
     * 课程搜索列表接口
     */
    public function searchcourse()
    {
        $kwd = $this->request->post('kwd');
        if(empty($kwd)){
            $this->error('请填写搜索词！');
        }
        $page = $this->request->post('page/d', 1);
        $pagesize = $this->request->post('pagesize/d', 15);
        $model = new SearchLogic();
        $data = $model->setKwd($kwd)->setOrgCateId(ORG_CATE_ID)->setPage($page)->setPagesize($pagesize)->getList();
        if($data){
            $this->success('', $data);
        }else{
            $this->error('暂无数据');
        }
    }


    /*热门搜索*/
    public function hotSearch() {
        $model = (new SearchLogic())->setOrgCateId(ORG_CATE_ID);
        $hot = $model->getHot();
        $history = $model->getHistory();

        $this->success('hot', [
            'hot'=> $hot,
            'history' => $history
        ]);
    }
}